﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Xml;
using Google.GData.Photos;
using Google.GData.Client;
using System.IO;
using System.Text;

/// <summary>
/// Summary description for PicasaImageFinder
/// </summary>
public class PicasaHelper
{

    public static AtomEntryCollection GetImagesByPhrase(string keyword)
    {
        if (keyword.ToLower()=="rowing")
        {
            return null;
        }
        PicasaService myService = new PicasaService("AutoView");
        myService.setUserCredentials("nyordanovads@gmail.com", "dessi777");
        PhotoQuery query = new PhotoQuery("http://picasaweb.google.com/data/feed/api/all");
        query.Query = keyword;
        query.Access = PicasaQuery.AccessLevel.AccessPublic;
        query.NumberToRetrieve = 10;
       


        PicasaFeed feed = myService.Query(query);
        //foreach (AtomEntry entry in feed.Entries)
        //{
        //    StringBuilder bd = new StringBuilder();
        //    XmlWriterSettings settings = new XmlWriterSettings();
        //    settings.ConformanceLevel = ConformanceLevel.Document;
        //    settings.OmitXmlDeclaration = true;

        //    XmlWriter wt = XmlWriter.Create(bd, settings);
        //    StreamWriter st = new StreamWriter(@"c:\1.xml");
        //    entry.SaveToXml(st.BaseStream);
        //    //byte[] bt=new byte[st.Length];
        //    //st.Read(bt, 0, (int)st.Length);
        //    //foreach (byte b in bt)
        //    //{
        //    //    bd.Append(b);   
        //    //}

        //    string temp = bd.ToString();


        //}
        return feed.Entries;
    }

}



//Accessing photo information

//In previous examples, only the title of a photo was printed out. However, there is a lot of different data that can be retrieved about a photo such as EXIF information, thumbnail URLs, the ID of the album it is a part of, and more.

//PhotoAccessor ac = new PhotoAccessor(entry);
//string albumId = ac.AlbumId;
//string photoId = ac.Id;
//string camera = "";
//if (entry.Exif.Make != null && entry.Exif.Model != null)
//{
//    camera = entry.Exif.Make.Value + " " + entry.Exif.Model.Value;
//}
//string contentUrl = entry.Media.Content.Attributes["url"] as string;
////grab the URL of the first thumbnail
//string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;

//Console.WriteLine("AlbumID: " + albumId);
//Console.WriteLine("PhotoID: " + photoId);
//Console.WriteLine("Camera: " + camera);
//Console.WriteLine("Content URL: " + contentUrl);
//Console.WriteLine("First Thumbnail: " + firstThumbUrl);

//}
